//package cn.autumnorange.app.common.consumer.rpc.lock;
//
//import cn.autumnorange.app.common.rpc.anntation.AnnotationContext;
//import cn.autumnorange.app.common.rpc.lock.RPCIdempotentLockTarget;
//import lombok.extern.slf4j.Slf4j;
//import org.aopalliance.aop.Advice;
//import org.aopalliance.intercept.MethodInterceptor;
//import org.aopalliance.intercept.MethodInvocation;
//import org.springframework.aop.ClassFilter;
//import org.springframework.aop.MethodMatcher;
//import org.springframework.aop.Pointcut;
//import org.springframework.aop.support.AbstractPointcutAdvisor;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.cloud.openfeign.FeignClient;
//import org.springframework.context.ApplicationContext;
//import org.springframework.stereotype.Component;
//
//import java.lang.annotation.Annotation;
//import java.lang.reflect.Method;
//import java.lang.reflect.Parameter;
//
//
///**
// * 横切aop拦截调用生产端加锁
// */
//@Slf4j
//@Component
//public class RedisCacheTargetHandleAdvisor extends AbstractPointcutAdvisor {
//    //    @Autowired
////    private TimeService timeService;
//    @Autowired
//    private ApplicationContext applicationContext;
//
//    @Value("${ribbon.ConnectTimeout}")
//    private long connectTimeout;
//
//    @Value("${ribbon.ReadTimeout}")
//    private long readTimeout;
//
//    @Value("${ribbon.MaxAutoRetries}")
//    private int maxAutoRetries;
//
//    @Value("${ribbon.MaxAutoRetriesNextServer}")
//    private int maxAutoRetriesNextServer;
//
//    public RedisCacheTargetHandleAdvisor() {
//        System.out.println("RedisCacheTargetHandle init!!!!");
//    }
//
//    public boolean existsAnnotation(Class<?> cs, Class<? extends Annotation> annotation) {
//        boolean rs = cs.isAnnotationPresent(annotation);
//        if (!rs) {
//            rs = cs.getSuperclass() != null && existsAnnotation(cs.getSuperclass(), annotation);
//        }
//        if (!rs) {
//            Class<?>[] interfaces = cs.getInterfaces();
//            for (Class<?> f : interfaces) {
//                rs = existsAnnotation(f, annotation);
//                if (rs) {
//                    break;
//                }
//            }
//        }
//        if (!rs) {
//            Annotation[] annotations = cs.getAnnotations();
//            for (Annotation an : annotations) {
//                rs = annotation.isAssignableFrom(an.getClass());
//                if (rs) {
//                    break;
//                }
//            }
//        }
//        return rs;
//    }
//
//    @Override
//    public Pointcut getPointcut() {
//        return new Pointcut() {
//            @Override
//            public ClassFilter getClassFilter() {
////                return (Class<?> clazz) -> existsAnnotation(clazz, FeignCl.class);
//             return  new ClassFilter() {
//                    @Override
//                    public boolean matches(Class<?> aClass) {
//                        return existsAnnotation(aClass, RedisCacheTarget.class);
//                    }
//                };
//            }
//
//            @Override
//            public MethodMatcher getMethodMatcher() {
//                return MethodMatcher.TRUE;
//            }
//        };
//    }
//
//    @Override
//    public Advice getAdvice() {
//
//        return (MethodInterceptor)
//                (MethodInvocation invocation) -> {
//                    RedisCacheReadAnnotationnStrategy redisCacheAnnotationnStrategy= new RedisCacheReadAnnotationnStrategy(invocation,applicationContext,readTimeout,connectTimeout);
//                    AnnotationContext annotationContext= AnnotationContext.getAnnotationContext();
//                    annotationContext.putAnnotationStrategy(RedisCacheTarget.class.getName(),redisCacheAnnotationnStrategy);
//                    Method method=invocation.getMethod();
//                    String methodName = annotationContext.getMethodAllMSG(method);
//                    String className = invocation.getMethod().getDeclaringClass().getName();
//                    return  annotationContext.annotationTargetHandle(className,methodName,RedisCacheTarget.class.getName(),true,true);
//        };
//    }
//}
